package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/05 20:19
 **/
public class Day21_2_Num12_IntToRoman {
    class Solution {
        public String intToRoman(int num) {
            String res = "";
            int[] data = new int[]{1,4,5,9,10,40,50,90,100,400,500,900,1000};
            String[] str = new String[]{"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};

            for(int i = 12;i >= 0;i--){
                int value = data[i];
                data[i] = num/data[i];
                num -= (value * data[i]);

                while (data[i]-- > 0){
                    res += str[i];
                }
            }
            return res;
        }
    }
}